Homework 11: Introduction to Python

CS 110 • 10 Points Total
Due on-line Wed. May 2, 2018

Objectives

Assignment

Download and install Python. You can get it from http://www.python.org/. Click on "Downloads" from the menu bar on the left of the screen. You will need to choose what version to install on your computer. For my PC running Windows, the Python web site gave me a file called "python-2.7.14.msi" to download. Download and save the correct file for your computer onto your desktop. For my PC, I was prompted to install the "all users" option. Follow the prompts to complete your installation. We will discuss in class whether to install Python 2 or 3. Python 2 is version 2.7.14, while Python 3 is version 3.6.3, as of this writing.

For each of the following questions, type in the given code and record the results as your answer. I need to be able to clearly see each of the inputs and outputs from the list below. You should be able to cut and paste your work into a Word document to hand in. (1 pt each for the first 6 items, then 4 pts for the Python file (last) part = 10 pts )

  1. Print statement
    >>>print "hello"
    >>>print ("hello")
    

  2. Addition
    >>>a=3
    >>>a
    >>>b=7
    >>>b
    >>>a+b
    

  3. Data types
    >>>c=5.3
    >>>c
    >>>int(c)
    >>>float(c)
    

  4. More arithmetic and data types
    >>>15/2
    >>>15.0/2.0
    >>>456 % 10
    >>>456 / 10
    >>>456.0 / 10.0
    >>>2+3
    >>>"2"+"3"
    >>>r=3
    >>>r
    >>>print 3.14159*r**2
    

  5. Lists with a comment
    >>>print ["E", "F", "F"]      # a list of strings
    >>>print [2, 4, 6, 8]         # a list of numbers
    

  6. Logic
    >>> n=5
    >>> n
    >>> n==0
    >>> n!=0
    >>> n==5
    

  7. Create a Python file
    
    
    
    From the Python shell, select File → New Window.
    In that new window, type in two separate print statements of your choice, for example:
    the statement to print "Python programming" on one line, and "Is Fun" on another line. Use your own example.
    Then, select Run → Run Module. It may prompt you to save the file. If so, give it a name like
    "printtest.py", and place it where you can find it, e.g. on your desktop. Watch what happens when you run the
    module. Briefly describe what happened, using screen shot(s) (i.e. Alt Print-Screen on a PC), or, a word
    description, or both.
    

Type your name, "CS 110 HW11: Introduction to Python", and the date completed --- at the top of your paper and upload into Blackboard Learn by the due date. Remember the filenaming convention of Lastname_Firstname_HW11.docx or something similar.